iT邦幫忙

2024 iThome 鐵人賽

DAY 8
0
Security

「後量子密碼學」- 未來資訊安全的基礎系列 第 8

Day8(NTRU)「吾乃數論學家」晶格密碼學二 - 說好的晶格

  • 分享至 

  • xImage
  •  

今天我們來解釋昨天介紹的「吾乃數論學家」為何是晶格密碼學?
與之前的二維晶格相似,關鍵都在解碼的正確性

回顧解碼正確性的證明

之所以解碼會成功,主要原因是因為

https://ithelp.ithome.com.tw/upload/images/20240919/20168745W6BKZeR46A.png

之右手邊部分的係數可以被控制,所以我們可以還原出整數上的等號(非模除上的等號),然後再做後續的有號提升與模除 p 運算。

意思是,如果我們想要偽造一個假的密鑰 (f(x), g(x)) ,那他只要滿足

一、

https://ithelp.ithome.com.tw/upload/images/20240919/20168745K9j5mrmm2f.png

其中 h(x) 與 q 是公鑰的內容。

二、f(x) 與 g(x) 的係數都不大,以至於以下多項式的係數絕對值不超過 q/2。

https://ithelp.ithome.com.tw/upload/images/20240919/20168745kojcinKKz7.png

這個步驟是不是與之前看到的二維晶格非常雷同?😀

將多項式乘法寫為矩陣乘法

為了要用向量空間討論,我們應該介紹一個用矩陣乘法來寫的多項式乘法:

考慮在 R 底下的運算

https://ithelp.ithome.com.tw/upload/images/20240919/20168745QjoA81Junh.png

並將係數寫好

https://ithelp.ithome.com.tw/upload/images/20240919/2016874517SFIl3l5o.png

(以下的數學看過即可,我們會用程式驗證)
那麼根據在 R 底下的模除運算規則,我們知道

https://ithelp.ithome.com.tw/upload/images/20240919/20168745F3k1YLTyhb.png

為了進一步分析,我們將其寫成矩陣形式:

https://ithelp.ithome.com.tw/upload/images/20240919/20168745yVzKqwZiaD.png

簡寫為:

https://ithelp.ithome.com.tw/upload/images/20240919/201687454HQv2YgNXk.png

好,證明部分很無聊,我們用程式簡單驗證看看:

N = 11

# 多項式環
R_poly = quotient(PolynomialRing(ZZ,x),x^N-1)

# 隨機生成多項式
f = R_poly([randint(-10,10) for i in range(N)])
h = R_poly([randint(-10,10) for i in range(N)])

print("f =", f)
print("h =", h)

g = f*h
print("\ng = f * h =", g)


# Ouptuts:
# f = -6*xbar^10 + xbar^8 + 10*xbar^7 - 5*xbar^6 + xbar^5 + 3*xbar^4 - 6*xbar^3 + 7*xbar^2 + 7*xbar + 9
# h = xbar^10 + 5*xbar^9 - 9*xbar^8 - 7*xbar^7 + 2*xbar^6 - 5*xbar^5 + 7*xbar^4 - 3*xbar^3 + 4*xbar^2 - 7*xbar - 6
# 
# g = f * h = -xbar^10 - 45*xbar^9 - 194*xbar^8 - 101*xbar^7 + 142*xbar^6 - 44*xbar^5 + 3*xbar^4 - 69*xbar^3 + 13*xbar^2 - 239*xbar + 157

呼叫 Matrix 類別,建構上面的 H 矩陣,並使用他內建的矩陣乘法:

f_coeff = f.list()
h_coeff = h.list()
g_coeff = g.list()


H = Matrix([[h_coeff[(i-j)%N] for i in range(N)] for j in range(N)])
print(H)
F = Matrix([[f_coeff[i] for i in range(N)]])

print(F)
print("\n")
print(F*H)
print(g_coeff)

# Outputs:
# [-6 -7  4 -3  7 -5  2 -7 -9  5  1]
# [ 1 -6 -7  4 -3  7 -5  2 -7 -9  5]
# [ 5  1 -6 -7  4 -3  7 -5  2 -7 -9]
# [-9  5  1 -6 -7  4 -3  7 -5  2 -7]
# [-7 -9  5  1 -6 -7  4 -3  7 -5  2]
# [ 2 -7 -9  5  1 -6 -7  4 -3  7 -5]
# [-5  2 -7 -9  5  1 -6 -7  4 -3  7]
# [ 7 -5  2 -7 -9  5  1 -6 -7  4 -3]
# [-3  7 -5  2 -7 -9  5  1 -6 -7  4]
# [ 4 -3  7 -5  2 -7 -9  5  1 -6 -7]
# [-7  4 -3  7 -5  2 -7 -9  5  1 -6]
# [ 9  7  7 -6  3  1 -5 10  1  0 -6]
# 
# [ 157 -239   13  -69    3  -44  142 -101 -194  -45   -1]
# [157, -239, 13, -69, 3, -44, 142, -101, -194, -45, -1]

可以發現,兩個結果是一樣的,所以我們已驗證這個等式的正確性。

將 f(x) 與 g(x) 寫成短向量:

先做成向量

首先,因為 f(x) 與 g(x) 應滿足

https://ithelp.ithome.com.tw/upload/images/20240919/20168745r415w6ea2w.png

所以我們可以改寫為

https://ithelp.ithome.com.tw/upload/images/20240919/20168745zyeycO0vmX.png

u(x) 是某個在 R 裡面的多項式。

因此我們可以故技重施:

https://ithelp.ithome.com.tw/upload/images/20240919/201687452jgXXFMTXw.png

現在我們嘗試將這個寫成「係數的向量」:首先對付 f(x)(1, h(x))

https://ithelp.ithome.com.tw/upload/images/20240919/20168745KAGU15tkdU.png

而左邊可以寫為以下矩陣乘法

https://ithelp.ithome.com.tw/upload/images/20240919/20168745pdd3VgwEQX.png

我們把它記作

https://ithelp.ithome.com.tw/upload/images/20240919/20168745sKgf6aWY8j.png

接著對付 -u(x)(0, q)

https://ithelp.ithome.com.tw/upload/images/20240919/201687458xsy8d1Qyl.png

我們把它記作

https://ithelp.ithome.com.tw/upload/images/20240919/20168745gZ2lTlSxXE.png

因此,

https://ithelp.ithome.com.tw/upload/images/20240919/20168745Kf4qwW6pBg.png

可以寫為

https://ithelp.ithome.com.tw/upload/images/20240919/201687450Ulz0ii7QK.png

或整更簡潔地

https://ithelp.ithome.com.tw/upload/images/20240919/20168745O01pHpK3mn.png

短向量問題

好的,接著我們來分析這個矩陣方程式

https://ithelp.ithome.com.tw/upload/images/20240919/20168745dKnzGlJTNJ.png

左手邊是一個 2N 維度的向量,我們希望他越小越好。

右手邊可以看成是矩陣

https://ithelp.ithome.com.tw/upload/images/20240919/20168745oe1ggRDYxc.png

其行向量的整係數 (f_0, ..., f_N-1, -u_0, ..., -u_N-1) 線性組合

引此我們在做的其實是決定好整係數

https://ithelp.ithome.com.tw/upload/images/20240919/20168745Qzu24orWbN.png

好讓他的結果向量

https://ithelp.ithome.com.tw/upload/images/20240919/20168745DolM4AICzZ.png

儘量的小。

恭喜,這就是標準的晶格短向量問題。

明天是第九天,是晶格密碼學的最後一篇,我們會帶過相關的攻擊方式,並介紹一些其他的加密標準。

Takeaway

  • 多項式乘法可以用矩陣來寫,除了可以用代數證明以外,我們也可以寫程式來確認該等式。
  • NTRU 密碼系統的解碼正確性依賴於參與其中的多項式的係數夠小
  • 承上,也因此我們可以把尋找 f(x) 與 g(x) 的過程看為「尋找短向量」

上一篇
Day7 (NTRU)「吾乃數論學家」晶格密碼學一
下一篇
Day 9 晶格密碼學的攻擊與小結
系列文
「後量子密碼學」- 未來資訊安全的基礎15
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言